package  org.fantasy.common.db.center;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import  org.fantasy.common.compile.CompileCenter;
import  org.fantasy.common.db.QryFactory;
import  org.fantasy.common.db.Query;

public class QryCenterFactoryImpl implements QryCenterFactory{
    
    private transient final Log log = LogFactory.getLog(getClass());

    private QryFactory qryFactory;

    private CompileCenter compileCenter;
    
    public QryCenterFactoryImpl(){
        
    }

    public void setQryFactory(QryFactory qryFactory) {
        this.qryFactory = qryFactory;
    }

    public void setCompileCenter(CompileCenter compileCenter) {
        this.compileCenter = compileCenter;
    }

    /**
     * 返回QryService接口
     * 
     * @param queryId
     * @param paramMap
     * @return
     */
    public QryCenter getQryCenter(String queryId, Map<String, Object> paramMap) {
        QryCenterImpl qryCenter = new QryCenterImpl(queryId,paramMap);
        qryCenter.setCompileCenter(compileCenter);
        qryCenter.setQryFactory(qryFactory);
        return qryCenter;
    }
    
    public QryCenter getQryCenter(String sqlId) {
        return getQryCenter(sqlId,new HashMap<String, Object>());
    }
    
    /**
     * 返回Query接口
     * 
     * @param queryId
     * @param paramMap
     * @return
     */
    public Query getQuery(String sql , Map<String, Object> paramMap) {
        return qryFactory.getQuery(sql,paramMap);
    }
    
    /**
     * 返回Query接口
     * 
     * @param queryId
     * @param paramMap
     * @return
     */
    public Query getQuery(String sql) {
        return getQuery(sql,new HashMap<String, Object>());
    }
}
